#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
vector<LL>g[maxn];
LL vis1[maxn],vis2[maxn],a,b;
void dfs1(LL u){
    vis1[u]=1;
    for(LL i=0;i<g[u].size();i++){
        LL v=g[u][i];
        if(vis1[v]||v==b) continue;
        dfs1(v);
    }
}
void dfs2(LL u){
    vis2[u]=1;
    for(LL i=0;i<g[u].size();i++){
        LL v=g[u][i];
        if(v==a||vis2[v]) continue;
        dfs2(v);
    }
}
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   LL t;cin>>t;
   while(t--){
      LL n,m;cin>>n>>m>>a>>b;
      for(LL i=0;i<n+10;i++) g[i].clear(),vis1[i]=vis2[i]=0;
      for(LL i=1;i<=m;i++){
          LL u,v;cin>>u>>v;
          g[u].push_back(v);
          g[v].push_back(u);
      }
      dfs1(a);
      dfs2(b);
      LL sum1=0;LL sum2=0;
      for(LL i=1;i<=n;i++){
         ///cout<<vis1[i]<<" "<<vis2[i]<<"\n";
         if(!vis1[i]&&vis2[i]&&i!=b) sum1++;
         if(vis1[i]&&!vis2[i]&&i!=a) sum2++;
      }
      cout<<sum1*sum2<<"\n";
   }
   return 0;
}
